home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / _archvrs / unix / unzip51 / amiga / utime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-06  |  4.1 KB  |  170 lines

  1. /* utime.c */
  2.  
  3. #include <string.h>
  4. #include <time.h>
  5. #include <errno.h>
  6.  
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <libraries/dos.h>
  10. #include <libraries/dosextens.h>
  11. #ifdef AZTEC_C
  12. #  include <clib/exec_protos.h>
  13. #  include <clib/dos_protos.h>
  14. #  include <pragmas/exec_lib.h>
  15. #  include <pragmas/dos_lib.h>
  16. #  define ESRCH  ENOENT
  17. #  define EOSERR EIO
  18. int _OSERR;
  19. #else
  20. #  include <proto/exec.h>
  21. #  include <proto/dos.h>
  22. #endif
  23.  
  24. extern LONG sendpkt(struct MsgPort *,LONG,LONG[],LONG);
  25.  
  26. extern int _OSERR;
  27.  
  28. #ifndef SUCCESS
  29. #define SUCCESS (-1L)
  30. #define FAILURE 0L
  31. #endif
  32.  
  33. int utime(char *file, time_t timep[]);
  34.  
  35. int utime(file,timep)
  36. char *file;
  37. time_t timep[];
  38. {
  39.  
  40.     struct DateStamp date;
  41.     struct MsgPort *taskport;
  42.     struct FileLock *dirlock, *lock;
  43.     struct FileInfoBlock *fib;
  44.  
  45.     LONG argv[4];
  46.     UBYTE *ptr;
  47.     long ret;
  48.  
  49. /*  timep[1] -= timezone;   */
  50.  
  51.     date.ds_Days = timep[1] / 86400;
  52.     date.ds_Minute = (timep[1] - (date.ds_Days * 86400))/60;
  53.     date.ds_Tick = ( timep[1] - (date.ds_Days * 86400) -
  54.                                 (date.ds_Minute * 60)
  55.                    ) * TICKS_PER_SECOND;
  56.     date.ds_Days -= ((8*365+2));
  57.  
  58.     if( !(taskport = (struct MsgPort *)DeviceProc(file)) )
  59.     {
  60.         errno = ESRCH;          /* no such process */
  61.         _OSERR = IoErr();
  62.         return(-1);
  63.     }
  64.  
  65.     if( !(lock = (struct FileLock *)Lock(file,SHARED_LOCK)) )
  66.     {
  67.         errno = ENOENT;         /* no such file */
  68.         _OSERR = IoErr();
  69.         return(-1);
  70.     }
  71.  
  72.     if( !(fib = (struct FileInfoBlock *)AllocMem(
  73.         (long)sizeof(struct FileInfoBlock),MEMF_PUBLIC|MEMF_CLEAR)) )
  74.     {
  75.         errno = ENOMEM;         /* insufficient memory */
  76.         UnLock((BPTR)lock);
  77.         return(-1);
  78.     }
  79.  
  80.     if( Examine((BPTR)lock,fib)==FAILURE )
  81.     {
  82.         errno = EOSERR;         /* operating system error */
  83.         _OSERR = IoErr();
  84.         UnLock((BPTR)lock);
  85.         FreeMem((char *)fib,(long)sizeof(*fib));
  86.         return(-1);
  87.     }
  88.  
  89.     dirlock = (struct FileLock *)ParentDir((BPTR)lock);
  90.     ptr = (UBYTE *)AllocMem(64L,MEMF_PUBLIC);
  91.     strcpy((ptr+1),fib->fib_FileName);
  92.     *ptr = strlen(fib->fib_FileName);
  93.     FreeMem((char *)fib,(long)sizeof(*fib));
  94.     UnLock((BPTR)lock);
  95.  
  96.     /* now fill in argument array */
  97.  
  98.     argv[0] = (LONG)NULL;
  99.     argv[1] = (LONG)dirlock;
  100.     argv[2] = (LONG)&ptr[0] >> 2;
  101.     argv[3] = (LONG)&date;
  102.  
  103.     errno = ret = sendpkt(taskport,34L,argv,4L);
  104.  
  105.     FreeMem(ptr,64L);
  106.     UnLock((BPTR)dirlock);
  107.  
  108.     return(0);
  109.  
  110. } /* utime() */
  111. /*  sendpkt.c
  112.  *  by A. Finkel, P. Lindsay, C. Sheppner
  113.  *  returns Res1 of the reply packet
  114.  */
  115. /*
  116. #include <exec/types.h>
  117. #include <exec/memory.h>
  118. #include <libraries/dos.h>
  119. #include <libraries/dosextens.h>
  120. #include <proto/exec.h>
  121. #include <proto/dos.h>
  122. */
  123.  
  124. LONG sendpkt(pid,action,args,nargs)
  125. struct MsgPort *pid;            /* process identifier (handler message port) */
  126. LONG action,                    /* packet type (desired action)              */
  127.      *args,                     /* a pointer to argument list                */
  128.      nargs;                     /* number of arguments in list               */
  129. {
  130.  
  131.     struct MsgPort *replyport, *CreatePort();
  132.     struct StandardPacket *packet;
  133.     LONG count, *pargs, res1;
  134.  
  135.     replyport = (struct MsgPort *)CreatePort(0L,0L);
  136.     if( !replyport ) return(0);
  137.  
  138.     packet = (struct StandardPacket *)AllocMem(
  139.             (long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
  140.     if( !packet )
  141.     {
  142.         DeletePort(replyport);
  143.         return(0);
  144.     }
  145.  
  146.     packet->sp_Msg.mn_Node.ln_Name  = (char *)&(packet->sp_Pkt);
  147.     packet->sp_Pkt.dp_Link          = &(packet->sp_Msg);
  148.     packet->sp_Pkt.dp_Port          = replyport;
  149.     packet->sp_Pkt.dp_Type          = action;
  150.  
  151.     /* copy the args into the packet */
  152.     pargs = &(packet->sp_Pkt.dp_Arg1);      /* address of 1st argument */
  153.     for( count=0; count<nargs; count++ )
  154.         pargs[count] = args[count];
  155.  
  156.     PutMsg(pid,(struct Message *)packet);   /* send packet */
  157.  
  158.     WaitPort(replyport);
  159.     GetMsg(replyport);
  160.  
  161.     res1 = packet->sp_Pkt.dp_Res1;
  162.  
  163.     FreeMem((char *)packet,(long)sizeof(*packet));
  164.     DeletePort(replyport);
  165.  
  166.     return(res1);
  167.  
  168. } /* sendpkt() */
  169.  
  170.